<template>
	<view class="page">
		<tui-list-cell v-if="item.serExpressVo && item.serExpressVo.addressDetail" unlined :radius="true">
			<view class="tui-address">
				<view class="tui-none-addr">
					<image src="/static/images/index/map.png" class="tui-addr-img" mode="widthFix"></image>
					<text>奖品收货地址：</text>
				</view>
				<view>
					<view class="tui-userinfo">
						<text class="tui-name">{{ item.serExpressVo.realName }}</text>
						{{ item.serExpressVo.mobilePhone }}
					</view>
					<view class="tui-addr">
						<!-- <view class="tui-addr-tag">公司</view> -->
						<text>{{ item.serExpressVo.province + item.serExpressVo.city + (item.serExpressVo.district || '') + item.serExpressVo.addressDetail }}</text>
					</view>
				</view>
			</view>
			<view class="tui-bg-img"></view>
		</tui-list-cell>
		<view class="item">
			<view class="item-info">
				<view class="item-info-left">
					<!-- <image v-if="index % 2 == 0" class="avatar" :src="item.awardImg || '/static/images/mall/my/icon_gift_3x.png'"></image> -->
					<image class="avatar" :src="item.awardImg || '/static/images/mall/my/icon_fanxian_3x.png'"></image>
					<view class="base">
						<view class="base-item">
							<text class="name">{{ item.awardName }}</text>
							<text>* {{ item.awardUnitNum }}</text>
						</view>
						<view class="base-item ">
							<text class="base-hospital">来源:{{ item.spinWinName }}</text>
						</view>
					</view>
				</view>
				<view class="item-info-right">
					<!-- <text :class="statusClass">测色</text> -->
					<text :class="{ green: item.spinWinRecordState == 'finished' }" class="price">{{ item.spinWinRecordStateName }}</text>
				</view>
			</view>
			<view class="item-bottom">
				<text class="item-bottom-time">获奖时间：{{ item.createdTime }}</text>
				<!-- <text class="item-bottom-btn">查看</text> -->
			</view>
		</view>

		<view v-if="!(item.serExpressVo && item.serExpressVo.addressDetail)" class="tui-exit">
			<tui-button @tap="handleSetting" shape="circle" shadow height="88rpx">设置收货地址</tui-button>
		</view>
		<Loading v-if="loading" type="img"></Loading>
	</view>
</template>

<script>
import { spinWinAwardDetail, setSpinWinAwardAddress } from '@/service/spinwin.js';
export default {
	data() {
		return {
			item: {
				serExpressVo: {}
			},
			loading: true
		};
	},
	onLoad({ id }) {
		this.id = id;
		this.getSpinWinAwardDetail();
		this.$store.state.address = null;
	},
	onShow() {
		const address = this.$store.state.address;

		if (address) {
			setSpinWinAwardAddress({ userAddressId: address.id, id: this.id }, { loading: true }).then(v => {
				this.getSpinWinAwardDetail();
			});
		}
	},
	methods: {
		async getSpinWinAwardDetail() {
			try {
				this.loading = true;
				this.item = await spinWinAwardDetail({ id: this.id });

				const maps = {
					waitingSet: '等待发货',
					finished: '完成'
				};

				this.item.spinWinRecordStateName = maps[this.item.spinWinRecordState];
			} catch (e) {
				//TODO handle the exception
			} finally {
				this.loading = false;
			}
		},
		handleSetting() {
			uni.navigateTo({
				url: '../../shop/address/address?type=' + 'select'
			});
		}
	}
};
</script>

<style lang="scss" scoped>
view {
	display: flex;
	box-sizing: border-box;
}

.item {
	margin: 0 auto;
	width: 720upx;
	flex-direction: column;
	background-color: #ffffff;
	margin-top: 15upx;
	border-radius: 16upx;
	padding: 30upx;
	/* margin-left:16upx; */
}

.item-top {
	padding-bottom: 26upx;
	align-items: flex-end;
	justify-content: space-between;
	border-bottom-width: 1upx;
	border-bottom-color: #f5f5f5;
	.item-patient,
	.item-duration {
		align-items: center;
	}

	.item-patient {
		font-size: 26upx;
		color: #66789c;

		.item-patient-name {
			color: #323437;
		}
	}
	.item-duration {
		font-size: 26upx;
		color: #66789c;

		.item-duration-value {
			color: #323437;
		}
	}
}
.item-status-left {
	font-size: 34upx;
	color: #323437;
	line-height: 48upx;
	font-weight: bolder;
}
.item-status-right {
	color: #f87d6f;
	font-size: 24upx;
	line-height: 48upx;
}
.item-1 .item-status-right {
	color: #a9b6c7;
}
.item-2 .item-status-right {
	color: #45ceb3;
}
.item-3 .item-status-right {
	color: #3291f9;
}
.item-info {
	align-items: center;
	justify-content: space-between;
	padding-top: 26upx;

	.item-info-left {
		.avatar {
			width: 100upx;
			height: 100upx;
			border-radius: 70upx;
			margin-right: 20upx;
		}
		.base {
			flex-direction: column;
			.base-item {
				flex-direction: row;
				text {
					font-size: 26upx;
					line-height: 48upx;
					color: #323437;
					margin-right: 10upx;
				}
				.name {
					font-size: 32upx;
					font-weight: 500;
				}
			}
			.base-hospital {
				width: 350upx;
				lines: 1;
				text-overflow: ellipsis;
			}
		}
	}
	.item-info-right {
		flex-direction: column;
		align-items: flex-end;
		.order-status-unpaid {
			color: #f87d6f;
			font-size: 24upx;
		}
		.order-status-complete {
			color: #3291f9;
		}
		.order-status-paid {
			color: #45ceb3;
		}
		.order-status-canceled {
			color: #a9b6c7;
		}
		.price {
			font-size: 34upx;
			line-height: 50upx;
			color: #3291f9;
			font-weight: bolder;
		}
	}
}
.item-icon {
	width: 22upx;
	height: 22upx;
	margin-right: 12upx;
}
.item-label {
	font-size: 26upx;
	color: #66789c;
	line-height: 42upx;
}

.item-bottom {
	justify-content: space-between;
	align-items: center;
	margin-top: 30upx;
}
.item-bottom-time {
	color: #a9b6c7;
	font-size: 24upx;
	line-height: 48upx;
}
.item-bottom-btn {
	color: #ffffff;
	background-color: #3291f9;
	border-radius: 10upx;
	padding: 10upx 23upx;
}
.ml8 {
	margin-left: 8upx;
}
.ml6 {
	margin-left: 6upx;
}
.green {
	color: #19be6b !important;
}

.page {
	flex-direction: column;
}
.tui-exit {
	padding: 100rpx 24rpx;
}

.tui-address {
	display: block;
	min-height: 80rpx;
	padding: 10rpx 0;
	box-sizing: border-box;
	position: relative;
}

.tui-userinfo {
	font-size: 30rpx;
	font-weight: 500;
	line-height: 30rpx;
	padding-bottom: 12rpx;
}

.tui-name {
	font-size: 40upx;
	padding-right: 40rpx;
}

.tui-addr {
	font-size: 24rpx;
	word-break: break-all;
	padding-right: 25rpx;
}

.tui-addr-tag {
	padding: 5rpx 8rpx;
	flex-shrink: 0;
	background: $uni-color-primary;
	color: #fff;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	font-size: 25rpx;
	line-height: 25rpx;
	transform: scale(0.8);
	transform-origin: 0 center;
	border-radius: 6rpx;
}

.tui-bg-img {
	position: absolute;
	width: 100%;
	height: 8rpx;
	left: 0;
	bottom: 0;
	background: url('')
		repeat;
}

.tui-none-addr {
	height: 80rpx;
	padding-left: 5rpx;
	display: flex;
	align-items: center;
}

.tui-addr-img {
	width: 36rpx;
	height: 46rpx;
	display: block;
	margin-right: 15rpx;
}
</style>
